package com.xuelangyun.form.exterauth.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.xuelangyun.form.exterauth.dao.ISysExterAppPermsDao;
import com.xuelangyun.form.exterauth.entity.SysExterAppPermsApiEntity;
import com.xuelangyun.form.exterauth.service.ISysExterAppPermsService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("sysExterAppPermsService")
public class SysExterAppPermsApiServiceImpl extends ServiceImpl<ISysExterAppPermsDao, SysExterAppPermsApiEntity> implements ISysExterAppPermsService {

	@Override
	public List<SysExterAppPermsApiEntity> queryByAppId(String appId) {
		
		QueryWrapper<SysExterAppPermsApiEntity> query = new QueryWrapper<>();
		query.eq("app_id", appId);
		
		return list(query);
	}

	@Override
	public boolean deleteByAppId(String appId) {
		
		QueryWrapper<SysExterAppPermsApiEntity> query = new QueryWrapper<>();
		query.eq("app_id", appId);
		
		return remove(query);
	}

	@Override
	public boolean insertAll(String appId, List<String> perms) {
		
		List<SysExterAppPermsApiEntity> batch = new ArrayList<SysExterAppPermsApiEntity>();
		if(perms != null)
		for(String p : perms) {
			SysExterAppPermsApiEntity entity = new SysExterAppPermsApiEntity();
			entity.setAppId(appId);
			entity.setPermId(p);
			
			batch.add(entity);
		}
		
		 
		return saveBatch(batch);
	}

   

}
